package com.ljh.aop.proxy;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

/**
 * @author: Themberfue
 * @date: 2025/3/25 20:35
 * @description:
 */
public class User {
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
//        HouseProxy houseProxy = new HouseProxy(target);
//        houseProxy.saleHouse();

        // ! 使用 JDK 代理，只能代理接口
//        HouseSubject houseProxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class}, new JDKInvocation(target));
//        houseProxy.rentHouse();

        // ! 使用 CGLib 代理，既可以代理接口，又可以代理类
        HouseSubject houseProxy = (HouseSubject) Enhancer.create(target.getClass(), new CGlibMethodInterceptor(target));
        houseProxy.rentHouse();
    }
}
